//到货通知单
$(function(){
	//搜索
	$('.searchBar').click(function(){
		var thisform=$(this).parent('form');
		var order_no=thisform.find('input[name=order_no]').val();
		var company_name=thisform.find('input[name=company_name]').val();
		var mailNo=thisform.find('input[name=mailNo]').val();
		var receiveMan=thisform.find('input[name=receiveMan]').val();
		var print_status=thisform.find('input[name=print_status]').val();
		var start_time=thisform.find('input[name=start_time]').val();
		var end_time=thisform.find('input[name=end_time]').val();
		var logiscompany_name=thisform.find('input[name=logiscompany_name]').val();
		
		var goods_name=thisform.find('input[name=goods_name]').val();
		var nums=thisform.find('input[name=nums]').val();
		var check_cate=thisform.find('input[name=check_cate]').val();
		var pick_status=thisform.find('input[name=pick_status]').val();
		var is_delivery=thisform.find('input[name=is_delivery]').val();
		$('#printorderDatagrid').datagrid('options').pageNumber=1;//设置页码初始值为1
		$('#printorderDatagrid').datagrid({ 
			queryParams:{
				order_no:order_no,
				company_name:company_name,
				mailNo:mailNo,
				receiveMan:receiveMan,
				start_time:start_time,
				end_time:end_time,
				print_status:print_status,
				goods_name:goods_name,
				nums:nums,
				check_cate:check_cate,
				pick_status:pick_status,
				is_delivery:is_delivery,
				logiscompany_name:logiscompany_name
			}
		});
	})
	
	$('.AdvanceSearch').click(function(){
		$('#printAdvanceSearch').toggle(100);
	})

	$('#printorderDatagrid').datagrid({
		//url:getprintorderUrl+"?randnum="+Math.floor(Math.random()*1000000),
		url:getprintorderUrl,
		title:'面单管理',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		// {field:'ids',title:'',
				// formatter:function(value,rowData,index){
					// turl=scanorder_url;
					// turl=turl+"?mailNo="+rowData.logistics_no;
					// return "<a href='"+turl+"'>复核</a>";
				// }
		// },
		{field:'order_no',title:'订单编号',sortable:true},
		{field:'logistics_no',title:'电子面单号',sortable:true},
		{field:'logiscompany_name',title:'快递公司',sortable:true},
		{field:'user_name',title:'收件人姓名',sortable:true},
		{field:'user_phone',title:'收件人电话',sortable:true},
		{field:'province',title:'省',sortable:true},
		{field:'city',title:'市',sortable:true},
		{field:'area',title:'区',sortable:true},
		{field:'user_address',title:'收件人地址',width:'100px',
				formatter:function(val){
					return "<span title='"+val+"' alt='"+val+"' style='cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width:100px;float:left;'>"+val+"</span>";
				}
		},
		{field:'mark_mailno',title:'标签'},
		{field:'erp_mark_mailno',title:'erp备注'},
		{field:'pick_status',title:'已制单',sortable:true,
				formatter:function(value,rowData,index){
					if(value==0){
						return '否';
					}
					if(value==1){
						htmlobj=$.ajax({type:'post',url:get_picklist,data:{order_id:rowData.id},async:false});//ajax动态获取物流备案公司名称
						var info=eval('('+htmlobj.responseText+')');
						return info.message;
					}
				}
		},
		{field:'is_delivery',title:'已出库',sortable:true,
				formatter:function(val,rowData,rowIndex){
			       // console.log(rowData);
					if(val==0){
						return '否';
					}
					if(val==1){
						return '是';
					}
			    }},
		{field:'times',title:'打印次数',sortable:true,
				formatter:function(val,rowData,rowIndex){
			       // console.log(rowData);
					if(val!=0){
						return '(操作人:'+rowData.printer_name+')'+val;
					}
			    }
		},
		{field:'add_time',title:'推送时间',sortable:true},
		{field:'a.order_no',title:'商品编码',
				formatter:function(val,rowData,rowIndex){
			       // console.log(rowData);
					if(rowData.goods_list==null){
						return '没有商品详情';
					}
					var header="<table style='width:100%;'>";
					var footer="</table>";
					var body="";
					for(i=0;i<rowData.goods_list.length;i++){
						body=body+"<tr><td style='border:0px;'>"+rowData.goods_list[i].goods_no+"</td></tr>";
					}
					var text=header+body+footer;
					return text;
			    }
		},
		{field:'a.times',title:'商品名称',
				formatter:function(val,rowData,rowIndex){
			       // console.log(rowData);
					if(rowData.goods_list==null){
						return '没有商品详情';
					}
					var header="<table style='width:100%;'>";
					var footer="</table>";
					var body="";
					for(i=0;i<rowData.goods_list.length;i++){
						body=body+"<tr><td title='"+rowData.goods_list[i].goods_name+"' alt='"+rowData.goods_list[i].goods_name+"' style='border:0px;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;width:200px;float:left;'>"+rowData.goods_list[i].goods_name+"</td></tr>";
					}
					// body=body+"<tr height=10 border=0><td colspan='3'></td></tr>";
					var text=header+body+footer;
					return text;
			    }
		},
		{field:'b.times',title:'数量',
				formatter:function(val,rowData,rowIndex){
			       // console.log(rowData);
					if(rowData.goods_list==null){
						return '没有商品详情';
					}
					var header="<table style='width:100%;'>";
					var footer="</table>";
					var body="";
					for(i=0;i<rowData.goods_list.length;i++){
						body=body+"<tr><td style='border:0px;'>"+rowData.goods_list[i].goods_nums+"</td></tr>";
					}
					// body=body+"<tr height=10 border=0><td colspan='3'></td></tr>";
					var text=header+body+footer;
					return text;
			    }
		}
		]],
		view: detailview,
		detailFormatter: function(rowIndex,rowData){
			// console.log(rowData);
			if(rowData.goods_list==null){
				return '没有商品详情';
			}
			var header="<table style='width:50%;margin-bottom:10px;'><tr style='background:#F5F5F5'><td>商品编码</td><td>商品名称</td><td>数量</td></tr>";
			var footer="</table>";
			var body="";
			for(i=0;i<rowData.goods_list.length;i++){
				body=body+"<tr><td>"+rowData.goods_list[i].goods_no+"</td><td>"+rowData.goods_list[i].goods_name+"</td><td>"+rowData.goods_list[i].goods_nums+"</td></tr>";
			}
			// body=body+"<tr height=10 border=0><td colspan='3'></td></tr>";
			var text=header+body+footer;
			return text;
		},
		expand:true,
		onBeforeLoad:function(data){
			// console.log(data);
			data.first_orderid=$('#first_orderid').val();
        },
		onLoadSuccess: function (data) {
		  first_orderid=eval(data).first_orderid;
		  $('#first_orderid').val(first_orderid);
		},
		onLoadError:function(data){
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
	});
});
printorderObj={
	showAll:function(){		//显示默认条件下所有数据
		$('#first_orderid').val('');
		$('#printorderDatagrid').datagrid({ queryParams:''});
	},
	showAdvanceBar:function(){
		$('#printorderDatagrid').datagrid({ queryParams:{show_advance:1}});
	},
	save:function(url){//编辑后保存数据
		$('#booksInfoEditForm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
            	var result=eval('('+result+')');
                if (!result.status){
                    $.messager.confirm('错误提示',result.message,function(r){
                    	$('#booksInfoEditDialog').dialog('close');
                    });
                }else{
                    $('#booksInfoEditDialog').dialog('close');      
                    $('#printorderDatagrid').datagrid('reload');    
                }
            }
        });
	},
	editBar:function(){//显示编辑框
		var booksInfoRow=$('#printorderDatagrid').datagrid('getSelections');
        if (booksInfoRow.length>1){		            	
            $.messager.alert('提示','一次只能修改一条记录!','info');
        }else if(booksInfoRow.length==1){            	
        	$('#booksInfoEditDialog').dialog('open').dialog('setTitle','编辑用户');
            $('#booksInfoEditForm').form('load',booksInfoRow[0]);
        }else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	printBarYT:function(){	//预览圆通面单
		var LODOP;
		LODOP=getLodop();
		var Row=$('#printorderDatagrid').datagrid('getSelections');
        if (Row.length>0){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					$.post(ajax_printbatYTUrl,{id:id,preview:1},function(result){
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							LODOP.PRINT_INIT("圆通面单打印");
							LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
							$(result.info).each(function(index,item){
							
								LODOP.NewPage();
								LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
								// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
								if(index+1==count){//已循环到最后一张，直接打印
									LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","圆通面单打印"+(index+1));//为每个打印单独设置任务名
									LODOP.PREVIEW();
									getStatusValue('PRINT_STATUS_OK',0,document.getElementById('T2'))
								}
							})
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                

		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	printBarST:function(){	//预览申通面单
		var LODOP;
		LODOP=getLodop();
		var Row=$('#printorderDatagrid').datagrid('getSelections');
        if (Row.length>0){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					$.post(ajax_printbatSTUrl,{id:id,preview:1},function(result){
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							LODOP.PRINT_INIT("圆通面单打印");
							LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
							$(result.info).each(function(index,item){
							
								LODOP.NewPage();
								LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
								// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
								if(index+1==count){//已循环到最后一张，直接打印
									LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","圆通面单打印"+(index+1));//为每个打印单独设置任务名
									LODOP.PREVIEW();
									getStatusValue('PRINT_STATUS_OK',0,document.getElementById('T2'))
								}
							})
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                

		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	printBarBSE:function(){	//预览百世英文面单
		var LODOP;
		LODOP=getLodop();
		var Row=$('#printorderDatagrid').datagrid('getSelections');
        if (Row.length>0){

                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					$.post(ajax_printbatBSEUrl,{id:id,preview:1},function(result){
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							LODOP.PRINT_INIT("百世面单打印");
							LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
							$(result.info).each(function(index,item){
							
								LODOP.NewPage();
								LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
								// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
								if(index+1==count){//已循环到最后一张，直接打印
									LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));//为每个打印单独设置任务名
									LODOP.PREVIEW();
									getStatusValue('PRINT_STATUS_OK',document.getElementById('T1').value,document.getElementById('T2'))
								}
							})
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                

		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	printBarBS:function(cod=0){//预览百世面单
		var LODOP;
		LODOP=getLodop();
		var Row=$('#printorderDatagrid').datagrid('getSelections');
        if (Row.length>0){

                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					
					if(cod==1){
						str={id:id,preview:1,cod:1};
					}else{
						str={id:id,preview:1};
					}
					$.post(ajax_printbatBSUrl,str,function(result){
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							LODOP.PRINT_INIT("百世面单打印");
							LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
							$(result.info).each(function(index,item){
							
								LODOP.NewPage();
								LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
								// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
								if(index+1==count){//已循环到最后一张，直接打印
									LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));//为每个打印单独设置任务名
									LODOP.PREVIEW();
									getStatusValue('PRINT_STATUS_OK',document.getElementById('T1').value,document.getElementById('T2'))
								}
							})
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                

		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	printBarZTO:function(){//预览中通面单
		var LODOP;
		LODOP=getLodop();
		var Row=$('#printorderDatagrid').datagrid('getSelections');
        if (Row.length>0){

                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					$.post(ajax_printbatZTOUrl,{id:id,preview:1},function(result){
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							LODOP.PRINT_INIT("中通面单打印");
							LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
							$(result.info).each(function(index,item){
							
								LODOP.NewPage();
								LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
								// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
								if(index+1==count){//已循环到最后一张，直接打印
									LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","中通面单打印"+(index+1));//为每个打印单独设置任务名
									LODOP.PREVIEW();
									getStatusValue('PRINT_STATUS_OK',document.getElementById('T1').value,document.getElementById('T2'))
								}
							})
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                

		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	printBarSF:function(){//预览顺丰面单
		var LODOP;
		LODOP=getLodop();
		var Row=$('#printorderDatagrid').datagrid('getSelections');
        if (Row.length>0){

                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					$.post(ajax_printbatSFUrl,{id:id,preview:1},function(result){
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							LODOP.PRINT_INIT("顺丰面单打印");
							LODOP.SET_PRINT_PAGESIZE(1,1000,1540,"");
							$(result.info).each(function(index,item){
							
								LODOP.NewPage();
								LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
								// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
								if(index+1==count){//已循环到最后一张，直接打印
									LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","顺丰面单打印"+(index+1));//为每个打印单独设置任务名
									LODOP.PREVIEW();
									getStatusValue('PRINT_STATUS_OK',document.getElementById('T1').value,document.getElementById('T2'))
								}
							})
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                

		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	excelBar:function(){	//导出excel
		var thisform=$('#printorderSearchForm');
		//	console.log(thisform);
		var order_no=thisform.find('input[name=order_no]').val();
		var mailNo=thisform.find('input[name=mailNo]').val();
		var receiveMan=thisform.find('input[name=receiveMan]').val();
		var start_time=thisform.find('input[name=start_time]').val();
		var end_time=thisform.find('input[name=end_time]').val();
		var company_name=thisform.find('input[name=company_name]').val();
		var print_status=thisform.find('input[name=print_status]').val();
		var logiscompany_name=thisform.find('input[name=logiscompany_name]').val();
		
		var goods_name=thisform.find('input[name=goods_name]').val();
		var nums=thisform.find('input[name=nums]').val();
		var check_cate=thisform.find('input[name=check_cate]').val();
		var pick_status=thisform.find('input[name=pick_status]').val();
		var is_delivery=thisform.find('input[name=is_delivery]').val();
		console.log(order_no);
		url=getprintorderUrl+"&excel=1&rows=6000";
		if(order_no!=''){
			url=url+"&order_no="+order_no;
		}
		if(mailNo!=''){
			url=url+"&mailNo="+mailNo;
		}
		if(receiveMan!=''){
			url=url+"&receiveMan="+receiveMan;
		}
		if(start_time!=0){
			url=url+"&start_time="+start_time;
		}
		if(end_time!=0){
			url=url+"&end_time="+end_time;
		}
		if(company_name!=''){
			url=url+"&company_name="+company_name;
		}
		if(print_status!=''){
			url=url+"&print_status="+print_status;
		}
		if(logiscompany_name!=''){
			url=url+"&logiscompany_name="+logiscompany_name;
		}
		if(goods_name!=''){
			url=url+"&goods_name="+goods_name;
		}
		if(nums!=''){
			url=url+"&nums="+nums;
		}
		if(check_cate!=''){
			url=url+"&check_cate="+check_cate;
		}
		if(pick_status!=''){
			url=url+"&pick_status="+pick_status;
		}
		if(is_delivery!=''){
			url=url+"&is_delivery="+is_delivery;
		}
		window.location.href=url;
	},
	weightBar:function(){
		window.parent.closeTab('称重');
		window.parent.showTab(weighturl_green,'称重');
	},
	reloadBar:function(){//刷新数据
		$('#printorderDatagrid').datagrid('reload');
	},
	goprintYT:function(){//立即打印圆通面单
		var LODOP;
		LODOP=getLodop();
		
		var Row=$('#printorderDatagrid').datagrid('getSelections');
		var text='确定打印吗！';
        if (Row.length>0){
        	$.messager.confirm('打印提示',text,function(r){
                if(r){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					// console.log(id);
					// return false;
					$.post(ajax_printbatYTUrl,{id:id},function(result){
						// console.log(result);
						// return false;
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							// alert(count);
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							var printer_value;//打印机返回值
							$(result.info).each(function(index,item){
								// console.log(item);
								// return false;
								if(index%eachvar==0){
									// alert(index+1==count);
									LODOP.PRINT_INIT("圆通面单打印");
									LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
									if(index+1==count){//已循环到最后一张，直接打印
										// alert(123);
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","圆通面单打印"+(index+1));//为每个打印单独设置任务名
										// LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
										// if (LODOP.CVERSION) {
											// LODOP.On_Return=function(TaskID,Value){
												// printer_value=Value;//获得打印机id返回值
												// if (LODOP.CVERSION) LODOP.On_Return=function(TaskID,Value){
													// alert(Value);
												// };//获得打印机打印任务状态返回值
												// var strResult=LODOP.GET_VALUE('PRINT_STATUS_OK',printer_value);
												// if (!LODOP.CVERSION) return strResult; else return "";
											// };
											// LODOP.PRINT();
											// return;
										// } else printer_value=LODOP.PRINT();
										LODOP.PRINT();
									}
								}else{
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									
									if(index+1==count){//已循环到最后一张，直接打印
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","圆通面单打印"+(index+1));
										LODOP.PRINT();
									}else{
										if((index+1)%eachvar==0){//当前组的最后一张，可以打印
											LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","圆通面单打印"+(index+1));
											LODOP.PRINT();
										}
									}
								}
							})
							$('#printorderDatagrid').datagrid('reload');
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                }
        	});
		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	goprintST:function(){//立即打印申通面单
		var LODOP;
		LODOP=getLodop();
		
		var Row=$('#printorderDatagrid').datagrid('getSelections');
		var text='确定打印吗！';
        if (Row.length>0){
        	$.messager.confirm('打印提示',text,function(r){
                if(r){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					// console.log(id);
					// return false;
					$.post(ajax_printbatSTUrl,{id:id},function(result){
						// console.log(result);
						// return false;
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							// alert(count);
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							var printer_value;//打印机返回值
							$(result.info).each(function(index,item){
								// console.log(item);
								// return false;
								if(index%eachvar==0){
									// alert(index+1==count);
									LODOP.PRINT_INIT("申通面单打印");
									LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
									if(index+1==count){//已循环到最后一张，直接打印
										// alert(123);
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","圆通面单打印"+(index+1));//为每个打印单独设置任务名
										// LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
										// if (LODOP.CVERSION) {
											// LODOP.On_Return=function(TaskID,Value){
												// printer_value=Value;//获得打印机id返回值
												// if (LODOP.CVERSION) LODOP.On_Return=function(TaskID,Value){
													// alert(Value);
												// };//获得打印机打印任务状态返回值
												// var strResult=LODOP.GET_VALUE('PRINT_STATUS_OK',printer_value);
												// if (!LODOP.CVERSION) return strResult; else return "";
											// };
											// LODOP.PRINT();
											// return;
										// } else printer_value=LODOP.PRINT();
										LODOP.PRINT();
									}
								}else{
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									
									if(index+1==count){//已循环到最后一张，直接打印
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","圆通面单打印"+(index+1));
										LODOP.PRINT();
									}else{
										if((index+1)%eachvar==0){//当前组的最后一张，可以打印
											LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","圆通面单打印"+(index+1));
											LODOP.PRINT();
										}
									}
								}
							})
							$('#printorderDatagrid').datagrid('reload');
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                }
        	});
		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	goprintBSE:function(){//立即打印百世英文面单
		var LODOP;
		LODOP=getLodop();
		
		var Row=$('#printorderDatagrid').datagrid('getSelections');
		var text='确定打印吗！';
        if (Row.length>0){
        	$.messager.confirm('打印提示',text,function(r){
                if(r){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					// console.log(id);
					// return false;
					$.post(ajax_printbatBSEUrl,{id:id},function(result){
						// console.log(result);
						// return false;
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							// alert(count);
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							var printer_value;//打印机返回值
							$(result.info).each(function(index,item){
								// console.log(item);
								// return false;
								if(index%eachvar==0){
									// alert(index+1==count);
									LODOP.PRINT_INIT("百世面单打印");
									LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
									if(index+1==count){//已循环到最后一张，直接打印
										// alert(123);
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));//为每个打印单独设置任务名
										// LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
										// if (LODOP.CVERSION) {
											// LODOP.On_Return=function(TaskID,Value){
												// printer_value=Value;//获得打印机id返回值
												// if (LODOP.CVERSION) LODOP.On_Return=function(TaskID,Value){
													// alert(Value);
												// };//获得打印机打印任务状态返回值
												// var strResult=LODOP.GET_VALUE('PRINT_STATUS_OK',printer_value);
												// if (!LODOP.CVERSION) return strResult; else return "";
											// };
											// LODOP.PRINT();
											// return;
										// } else printer_value=LODOP.PRINT();
										LODOP.PRINT();
									}
								}else{
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									
									if(index+1==count){//已循环到最后一张，直接打印
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));
										LODOP.PRINT();
									}else{
										if((index+1)%eachvar==0){//当前组的最后一张，可以打印
											LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));
											LODOP.PRINT();
										}
									}
								}
							})
							$('#printorderDatagrid').datagrid('reload');
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                }
        	});
		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	goprintBS:function(cod=0){//立即打印百世面单
		var LODOP;
		LODOP=getLodop();
		
		var Row=$('#printorderDatagrid').datagrid('getSelections');
		var text='确定打印吗！';
        if (Row.length>0){
        	$.messager.confirm('打印提示',text,function(r){
                if(r){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					// console.log(id);
					// return false;
					if(cod==1){
						str={id:id,cod:1};
					}else{
						str={id:id};
					}
					$.post(ajax_printbatBSUrl,str,function(result){
						// console.log(result);
						// return false;
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							// alert(count);
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							var printer_value;//打印机返回值
							$(result.info).each(function(index,item){
								// console.log(item);
								// return false;
								if(index%eachvar==0){
									// alert(index+1==count);
									LODOP.PRINT_INIT("百世面单打印");
									LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
									if(index+1==count){//已循环到最后一张，直接打印
										// alert(123);
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));//为每个打印单独设置任务名
										// LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
										// if (LODOP.CVERSION) {
											// LODOP.On_Return=function(TaskID,Value){
												// printer_value=Value;//获得打印机id返回值
												// if (LODOP.CVERSION) LODOP.On_Return=function(TaskID,Value){
													// alert(Value);
												// };//获得打印机打印任务状态返回值
												// var strResult=LODOP.GET_VALUE('PRINT_STATUS_OK',printer_value);
												// if (!LODOP.CVERSION) return strResult; else return "";
											// };
											// LODOP.PRINT();
											// return;
										// } else printer_value=LODOP.PRINT();
										LODOP.PRINT();
									}
								}else{
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									
									if(index+1==count){//已循环到最后一张，直接打印
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));
										LODOP.PRINT();
									}else{
										if((index+1)%eachvar==0){//当前组的最后一张，可以打印
											LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));
											LODOP.PRINT();
										}
									}
								}
							})
							$('#printorderDatagrid').datagrid('reload');
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                }
        	});
		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	goprintZTO:function(){//立即打印中通面单
		var LODOP;
		LODOP=getLodop();
		
		var Row=$('#printorderDatagrid').datagrid('getSelections');
		var text='确定打印吗！';
        if (Row.length>0){
        	$.messager.confirm('打印提示',text,function(r){
                if(r){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					// console.log(id);
					// return false;
					$.post(ajax_printbatZTOUrl,{id:id},function(result){
						// console.log(result);
						// return false;
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							// alert(count);
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							var printer_value;//打印机返回值
							$(result.info).each(function(index,item){
								// console.log(item);
								// return false;
								if(index%eachvar==0){
									// alert(index+1==count);
									LODOP.PRINT_INIT("百世面单打印");
									LODOP.SET_PRINT_PAGESIZE(1,1000,1810,"");
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
									if(index+1==count){//已循环到最后一张，直接打印
										// alert(123);
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));//为每个打印单独设置任务名
										// LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
										// if (LODOP.CVERSION) {
											// LODOP.On_Return=function(TaskID,Value){
												// printer_value=Value;//获得打印机id返回值
												// if (LODOP.CVERSION) LODOP.On_Return=function(TaskID,Value){
													// alert(Value);
												// };//获得打印机打印任务状态返回值
												// var strResult=LODOP.GET_VALUE('PRINT_STATUS_OK',printer_value);
												// if (!LODOP.CVERSION) return strResult; else return "";
											// };
											// LODOP.PRINT();
											// return;
										// } else printer_value=LODOP.PRINT();
										LODOP.PRINT();
									}
								}else{
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									
									if(index+1==count){//已循环到最后一张，直接打印
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));
										LODOP.PRINT();
									}else{
										if((index+1)%eachvar==0){//当前组的最后一张，可以打印
											LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","百世面单打印"+(index+1));
											LODOP.PRINT();
										}
									}
								}
							})
							$('#printorderDatagrid').datagrid('reload');
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                }
        	});
		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	},
	goprint:function(){//立即打印顺丰面单
		var LODOP;
		LODOP=getLodop();
		
		var Row=$('#printorderDatagrid').datagrid('getSelections');
		var text='确定打印吗！';
        if (Row.length>0){
        	$.messager.confirm('打印提示',text,function(r){
                if(r){
                	var ids=[];
                	for(var i=0;i<Row.length;i++){
                		ids.push(Row[i].id);
                	}
                	var id=ids.join(',');
					// console.log(id);
					// return false;
					$.post(ajax_printbatSFUrl,{id:id},function(result){
						// console.log(result);
						// return false;
						if (!result.status){
							$.messager.alert('错误提示',result.message,'error');
						}else{
							// LODOP.ADD_PRINT_HTM(0,0,"100%","100%",result.info);
							count=result.info.length;
							// alert(count);
							var pagesize=10;//每组页数
							if(count>pagesize){
								var eachvar=pagesize;
							}else{
								var eachvar=count;
							}
							var printer_value;//打印机返回值
							$(result.info).each(function(index,item){
								// console.log(item);
								// return false;
								if(index%eachvar==0){
									// alert(index+1==count);
									LODOP.PRINT_INIT("顺丰面单打印");
									LODOP.SET_PRINT_PAGESIZE(1,1000,1540,"");
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									// LODOP.ADD_PRINT_TEXT(0,0,100,20,index);//测试
									if(index+1==count){//已循环到最后一张，直接打印
										// alert(123);
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","顺丰面单打印"+(index+1));//为每个打印单独设置任务名
										// LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
										// if (LODOP.CVERSION) {
											// LODOP.On_Return=function(TaskID,Value){
												// printer_value=Value;//获得打印机id返回值
												// if (LODOP.CVERSION) LODOP.On_Return=function(TaskID,Value){
													// alert(Value);
												// };//获得打印机打印任务状态返回值
												// var strResult=LODOP.GET_VALUE('PRINT_STATUS_OK',printer_value);
												// if (!LODOP.CVERSION) return strResult; else return "";
											// };
											// LODOP.PRINT();
											// return;
										// } else printer_value=LODOP.PRINT();
										LODOP.PRINT();
									}
								}else{
									LODOP.NewPage();
									LODOP.ADD_PRINT_HTM(0,0,"100%","100%",item);
									
									if(index+1==count){//已循环到最后一张，直接打印
										LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","顺丰面单打印"+(index+1));
										LODOP.PRINT();
									}else{
										if((index+1)%eachvar==0){//当前组的最后一张，可以打印
											LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME","顺丰面单打印"+(index+1));
											LODOP.PRINT();
										}
									}
								}								
							})
							$('#printorderDatagrid').datagrid('reload');
						}
					},'json').error(function(data){
						var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
					});
                }
        	});
		}else{
			$.messager.alert('打印提示','请选择列表数据','error');
		}
	}
}